<!--bootstrap批量上传-->
<script type="text/javascript" src="__STATIC__/Zz22zzUI/localResizeIMG4/lrz.bundle.js"></script>
<script type="text/javascript">
function toFixed2(num){
	return parseFloat(+num.toFixed(2));
}
//上传
$('.J_h5upload_patch').on("change",'input',function(){
	var that = this;
	// 也可以传入图片路径：lrz('../demo.jpg', ...
	// for (var i=0, l=this.files.length; i<l; i++) {
	// 	lrz(this.files[i], {width: 600, quality:0.9}, function (results) {
	// 		lrzResult(results);
	// 	});
	// }

	var parent = $(this).parent().parent();
	var lr = $(this).parent();
	var ulBox = parent.find('ul');
	var maxnum = parent.data('maxnum');

	if (maxnum && ulBox.children().length >= maxnum) {
		layer.msg('上传图片不能超过'+maxnum+'张');
		return;
	};
	
	lr.removeClass('ready');
	lr.addClass('waiting');
	for (var i=0, l=that.files.length; i<l; i++) {
		 lrz(that.files[i], {width: 800, quality: 0.8})
			.then(function (rst) {
				var file = rst.origin;
				
				var html = '<li>';
				html += '<input type="hidden" name="fileName[]" value="'+file.name+'">';
				html += '<input type="hidden" name="fileType[]" value="'+file.type+'">';
				html += '<input type="hidden" name="fileSize[]" value="'+file.size+'">';
				html += '<input type="hidden" name="fileData[]" value="'+rst.base64+'">';
				html += '<div class="lr lr-ui success"><div class="lr-hint"><div class="lr-ready"><i class="fa fa-camera"></i><span>点击上传</span></div><div class="lr-waiting"><i class="fa fa-spinner icon-spin"></i></div></div><div class="lr-success"><div class="lr-remove"><i class="fa fa-trash"></i></div><img class="lr-img" src="'+rst.base64+'"></div><input type="file"></div></li>';

				ulBox.append(html);

				lr.removeClass('waiting');
				lr.addClass('ready');
			})
			.catch(function (err) {
				// 处理失败会执行
				console.log('err');
				alert(err);
			})
			.always(function () {
				 // 不管是成功失败，都会执行
			});
	}
});
//删除
$('.J_h5upload_patch').on("click",'.lr-remove',function(){
	var parent = $(this).parent().parent().parent();
	parent.remove();
});
//设置封面
$('.J_h5upload_patch').on("click",'.set_cover',function(){
	var ul = $(this).parent().parent();
	var thisLi = $(this).parent();
	ul.prepend(thisLi);
});
</script>
<!--bootstrap批量上传 END-->